/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sessionbean;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import supportlearning.entities.Assignment;
import supportlearning.entities.StaffProfile;
import supportlearning.entities.Subject;

/**
 *
 * @author Huy
 */
@Stateless
public class AssignmentFacade extends AbstractFacade<Assignment> implements AssignmentFacadeLocal {

    @PersistenceContext(unitName = "EprojectCMSSupportLearning-ejbPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public List<Assignment> selectAssignment(int subId) {
        Subject sub = em.find(Subject.class, subId);
        String sql = "SELECT a FROM Assignment a WHERE a.subject.subId = :subId";
        Query q = em.createQuery(sql);
        q.setParameter("subId", sub.getSubId());
        List<Assignment> list = q.getResultList();
        return list;
    }

    public AssignmentFacade() {
        super(Assignment.class);
    }

    public boolean RemoveAsm(int asmId) {
        Assignment asm= em.find(Assignment.class, asmId);
        if(asm==null){
            return false;
        }
        em.remove(asm);
        return true;
    }
    @Override
   public void create(Assignment assignment){
        em.persist(assignment);
    }

    
   
}
